package com.spc.car.data.service.adm.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.spc.car.data.domain.adm.po.AdmVehicleInfoPO;
import com.spc.car.data.domain.adm.vo.AdmVehicleInfoVO;
import com.spc.car.data.entity.adm.AdmVehicleInfo;
import com.spc.car.data.mapper.adm.AdmVehicleInfoMapper;
import com.spc.car.data.service.adm.AdmVehicleInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.validation.constraints.NotNull;
import java.util.Date;
import java.util.Objects;

/**
 * <p>
 * 行政管理-车辆信息表 服务实现类
 * </p>
 *
 * @author 
 * @since 2020-04-28
 */
@Service
public class AdmVehicleInfoServiceImpl extends ServiceImpl<AdmVehicleInfoMapper, AdmVehicleInfo> implements AdmVehicleInfoService {


    @Override
    public boolean addOrUpdateVehicle(AdmVehicleInfoVO admVehicleInfoVO) {
        AdmVehicleInfo admVehicleInfo = new AdmVehicleInfo();
        BeanUtils.copyProperties(admVehicleInfoVO, admVehicleInfo);
        //编辑
        if (!Objects.isNull(admVehicleInfoVO.getId())) {
            admVehicleInfo.setUpdateTime(new Date());
            return updateById(admVehicleInfo);
        }

        admVehicleInfo.setCreateTime(new Date());
        return saveOrUpdate(admVehicleInfo);
    }

    @Override
    public AdmVehicleInfo getVehicleById(@NotNull Long id) {
        return getById(id);
    }

    @Override
    public IPage<AdmVehicleInfo> listForPage(AdmVehicleInfoPO admVehicleInfoPO) {
        Page page = page(admVehicleInfoPO.getPage(), admVehicleInfoPO.toWrapper());
        return page;
    }
}
